using System;
using System.Collections.Generic;
using System.Text;
using JobShopModel.Model.FactoryLvl;
using JobShopModel.Model.Station;
//TODO Documentation

namespace JobShopModel.Model.Job
{
    class Operation
    {
        public Time waitingTime;
        public Time operationTime;
        public Time blockedTime;

        private StationsList station;

        public StationsList Station
        {
            get { return station; }
            set 
            {
              throw new Exception("Illegal operation: Can not change the station for an operation after creation");               
            }
        }

        private Time meanServiceTime;

        private OperationStatus status;


        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="station"></param>
        /// <param name="meanServiceTime"></param>
        public Operation(StationsList station,Time meanServiceTime)
        {
            Status = OperationStatus.UNDONE;
            OperationTime = new Time(0,0.0);
            BlockedTime = new Time(0, 0.0);
            WaitingTime = new Time(0, 0.0);
            MeanServiceTime = meanServiceTime;
            this.station = station;
            
        }

        /**
         * Properties: 
         */
        #region Properties;

        internal Time WaitingTime
        {
            get { return waitingTime; }
            set { waitingTime = value; }
        }


        internal Time BlockedTime
        {
            get { return blockedTime; }
            set { blockedTime = value; }
        }


        internal Time OperationTime
        {
            get { return operationTime; }
            set { operationTime = value; }
        }

        internal Time MeanServiceTime
        {
            get { return meanServiceTime; }
            set
            {
                if (meanServiceTime == null)
                {
                    this.meanServiceTime = value;
                }
                else
                {
                    throw new Exception("Illegal Operation: Can not change the mean service time after creation");
                }
            }
        }

        public OperationStatus Status
        {
            get { return status; }
            set
            {
                if (value == OperationStatus.UNDONE && status != OperationStatus.DONE)
                {
                    status = value;
                }
                else if (status == OperationStatus.UNDONE && value == OperationStatus.DONE)
                {
                    status = value;
                }
                else
                {
                    throw new Exception("Illegal change of operation status:\n When an operation is done it can not be changed");
                }
            }
        }

        #endregion Properties;
    }
}
